<?php

namespace App\Listeners;

use App\Events\ExampleEvent;
use App\Events\OrderSuccessEvent;
use App\Models\Order;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use App\Jobs\OrderSuccessJob;

class WechatPushOrderSuccessListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  ExampleEvent  $event
     * @return void
     */
    public function handle(OrderSuccessEvent $event)
    {
        Log::info('WechatPushOrderSuccessListener');
        /** @var Order $order */
        $order = $event->order;

        dispatch(new OrderSuccessJob(
            $order->getUserId(),
            $order->getPaidAmount(),
            $order->getName(),
            $order->getTradeNo(),
            $order->items()->pluck('level')->toArray()
        ));

        Log::info('WechatPushOrderSuccessListener OrderSuccessJob');
    }
}
